import { ExceptionFilter, Catch } from '@nestjs/common';
import { GrpcException } from 'src/common/exception/grpc.execption';

@Catch()
export class GrpcFilter implements ExceptionFilter {
  catch(exception: any) {
    const isGrpcException = exception.details !== undefined;
    if (isGrpcException) {
      if (exception.code === 14) {
        exception.details = '出现错误：无法连接到Go服务。这是服务器的问题，请过一段时间再试。';
      }
      exception = new GrpcException(exception.details);
    }
    throw exception;
  }
}
